<?php
namespace app\admin\logic;
use app\admin\code\AdminCode;
use app\admin\code\BaseCode;
use app\admin\model\AdminModel;
use app\admin\model\AdModel;
use app\admin\validate\BaseValidate;
use think\Lang;
use think\Session;

class AdminLogic extends BaseLogic
{
    public function edit_password(BaseValidate $validate){
        if($this->_param['new_password'] != $this->_param['confirm_password']){
            $this->err = ['code'=>AdminCode::TWO_PASSWORD_IS_WRONG,Lang::get(AdminCode::TWO_PASSWORD_IS_WRONG)];
        }
        if($validate->validate($this->_param,__FUNCTION__) === false){
            $this->result = false;
            $this->err = $validate->getError();
            return false;
        }
        $model = new AdminModel();
        $data = [];
        $data['salt'] = rand(1000,9999);
        $data['pass_word'] = md5($this->_param['confirm_password'].$data['salt']);
        $model->save($data,['id'=>Session::get('admin.id')]);
        $this->result = true;
        return true;
    }
}


